/*
 * Copyright (c) 2015, CETIC.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the Institute nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/**
 * \file
 *         Simple CoAP Library
 * \author
 *         6LBR Team <6lbr@cetic.be>
 */
#ifndef LWM2M_DEVICE_OBJECT_H_
#define LWM2M_DEVICE_OBJECT_H_

#include "contiki.h"
#include "coap-common.h"
#include "lwm2m.h"

#ifdef LWM2M_CONF_DEVICE_OBJECT
#define LWM2M_DEVICE_OBJECT LWM2M_CONF_DEVICE_OBJECT
#else
#define LWM2M_DEVICE_OBJECT 1
#endif

#if LWM2M_DEVICE_OBJECT

#ifdef LWM2M_CONF_DEVICE_BATCH
#define LWM2M_DEVICE_BATCH LWM2M_CONF_DEVICE_BATCH
#else
#define LWM2M_DEVICE_BATCH 1
#endif

#ifdef LWM2M_CONF_DEVICE_MANUFACTURER
#define LWM2M_DEVICE_MANUFACTURER LWM2M_CONF_DEVICE_MANUFACTURER
#else
#define LWM2M_DEVICE_MANUFACTURER 1
#endif

#ifdef LWM2M_CONF_DEVICE_MODEL_NUMBER
#define LWM2M_DEVICE_MODEL_NUMBER LWM2M_CONF_DEVICE_MODEL_NUMBER
#else
#define LWM2M_DEVICE_MODEL_NUMBER 1
#endif

#ifdef LWM2M_CONF_DEVICE_SERIAL_NUMBER
#define LWM2M_DEVICE_SERIAL_NUMBER LWM2M_CONF_DEVICE_SERIAL_NUMBER
#else
#define LWM2M_DEVICE_SERIAL_NUMBER 1
#endif

#ifdef LWM2M_CONF_DEVICE_FIRMWARE
#define LWM2M_DEVICE_FIRMWARE LWM2M_CONF_DEVICE_FIRMWARE
#else
#define LWM2M_DEVICE_FIRMWARE 1
#endif

#ifdef LWM2M_CONF_DEVICE_REBOOT
#define LWM2M_DEVICE_REBOOT LWM2M_CONF_DEVICE_REBOOT
#else
#define LWM2M_DEVICE_REBOOT 1
#endif

#ifdef LWM2M_CONF_DEVICE_TIME
#define LWM2M_DEVICE_TIME LWM2M_CONF_DEVICE_TIME
#else
#define LWM2M_DEVICE_TIME 1
#endif

#if LWM2M_DEVICE_BATCH
#define LWM2M_DEVICE_BATCH_INIT() INIT_RESOURCE(device, LWM2M_INSTANCE_PATH(LWM2M_DEVICE_OBJECT_ID, LWM2M_DEFAULT_INSTANCE_ID));
#else
#define LWM2M_DEVICE_BATCH_INIT()
#endif

#if LWM2M_DEVICE_MANUFACTURER
#define LWM2M_DEVICE_MANUFACTURER_INIT() INIT_RESOURCE(device_manufacturer, LWM2M_DEVICE_PATH(LWM2M_DEVICE_MANUFACTURER_RESOURCE_ID));
#else
#define LWM2M_DEVICE_MANUFACTURER_INIT()
#endif

#if LWM2M_DEVICE_MODEL_NUMBER
#define LWM2M_DEVICE_MODEL_NUMBER_INIT() INIT_RESOURCE(device_model_number, LWM2M_DEVICE_PATH(LWM2M_DEVICE_MODEL_NUMBER_RESOURCE_ID));
#else
#define LWM2M_DEVICE_MODEL_NUMBER_INIT()
#endif

#if LWM2M_DEVICE_SERIAL_NUMBER
#define LWM2M_DEVICE_SERIAL_NUMBER_INIT() INIT_RESOURCE(device_serial_number, LWM2M_DEVICE_PATH(LWM2M_DEVICE_SERIAL_NUMBER_RESOURCE_ID));
#else
#define LWM2M_DEVICE_SERIAL_NUMBER_INIT()
#endif

#if LWM2M_DEVICE_FIRMWARE
#define LWM2M_DEVICE_FIRMWARE_INIT() INIT_RESOURCE(device_firmware, LWM2M_DEVICE_PATH(LWM2M_DEVICE_FIRMWARE_RESOURCE_ID));
#else
#define LWM2M_DEVICE_FIRMWARE_INIT()
#endif

#if LWM2M_DEVICE_REBOOT
#define LWM2M_DEVICE_REBOOT_INIT() INIT_RESOURCE(device_reboot, LWM2M_DEVICE_PATH(LWM2M_DEVICE_REBOOT_RESOURCE_ID));
#else
#define LWM2M_DEVICE_REBOOT_INIT()
#endif

#if LWM2M_DEVICE_TIME
#define LWM2M_DEVICE_TIME_INIT() INIT_RESOURCE(device_time, LWM2M_DEVICE_PATH(LWM2M_DEVICE_CURRENT_TIME_RESOURCE_ID));
#else
#define LWM2M_DEVICE_TIME_INIT()
#endif

#define LWM2M_DEVICE_OBJECT_DEFINE()

#define LWM2M_DEVICE_OBJECT_INIT() \
  LWM2M_DEVICE_BATCH_INIT(); \
  LWM2M_DEVICE_MANUFACTURER_INIT(); \
  LWM2M_DEVICE_MODEL_NUMBER_INIT(); \
  LWM2M_DEVICE_SERIAL_NUMBER_INIT(); \
  LWM2M_DEVICE_FIRMWARE_INIT(); \
  LWM2M_DEVICE_REBOOT_INIT(); \
  LWM2M_DEVICE_TIME_INIT();

#define LWM2M_DEVICE_OBJECT_LINK "<3/0>,"

#else /* LWM2M_DEVICE_OBJECT */

#define LWM2M_DEVICE_OBJECT_DEFINE()
#define LWM2M_DEVICE_OBJECT_INIT()
#define LWM2M_DEVICE_OBJECT_LINK

#endif /* LWM2M_DEVICE */

#endif /* LWM2M_DEVICE_H_ */
